<?php

namespace Home\Controller;

/**
 * Description of AdminController.class控制器实例
 * 
 * @author songanwei
 * @date 2016-1-4
 */
class AdminController extends ParentController {

    /**
     * @description 管理员用户视图页面
     * @modify songanwei 2016-01-04
     */
    public function index() {
        $where = $condition = array();
        $bpassLoginModel = D('BpassLogin');
        $count = $bpassLoginModel->where($where)->count();
        $Page = classPage($count);
        $data = $bpassLoginModel->where($where)->limit($Page->firstRow, $Page->listRows)->select();
        $page = $Page->show();
        $this->assign('adminData', $data);
        $this->assign('page', $page);
        $this->display();
    }

    /**
     * @description 修改密码视图页面
     * @modify songanwei 2016-03-17
     */
    public function password() {

        $this->display();
    }

    /**
     * @description 更新密码
     * @modify songanwei 2016-03-17
     */
    public function updatePassword() {
        $oldPassword = I('post.oldPassword');
        $newPassword = I('post.newPassword');
        //数据格式校验


        $adminId = getAdminId();
        $bpassLoginModel = D('BpassLogin');
        $bpassLogin = $bpassLoginModel->getInfo($adminId);
        if (!$bpassLogin) {
            $this->returnJson(403, 504);
        }

        //检查原密码
        if ($bpassLogin['password'] != $oldPassword) {
            $this->returnJson(403, 102);
        }
        //更新新密码
        $result = $bpassLoginModel->setPassword($adminId, $newPassword);
        if ($result == false) {
            $this->returnJson(403, 506);
        }
        $this->returnJson(200, 200);
    }

}
